<template>
  <div class="baseView">
    <div class="base_wrapper">
      <van-field
        readonly
        clickable
        name="picker"
        :value="value"
        label=""
        left-icon="location-o"
        size="large"
        placeholder="切换基地"
        @click="showPicker = true"
      >
        <template #extra>
          <van-button plain type="info" size="small">切换基地</van-button>
        </template>
      </van-field>
    </div>
    <van-popup v-model="showPicker" position="bottom">
      <van-picker
        show-toolbar
        :columns="baseLists"
        @confirm="onConfirm"
        @cancel="showPicker = false"
      />
    </van-popup>
  </div>
</template>

<script>
  import Util from "@/common/util";

  export default {
    name: "baseView",

    data() {
      return {
        value: this.baseLists[0].text,
        showPicker: false,
      };
    },

    props: {
      baseLists: {
        type: Array,
        default() {
          return []
        }
      },
    },

    methods: {
      onConfirm(value) {
        this.value = value.text;
        Util.storage.set('base_id', value.base_id)
        this.showPicker = false;
      },
    },
  }
</script>

<style scoped>
  .base_wrapper {
    font-size: .36rem;
  }
  .base_wrapper >>> .van-field__control{
    font-size: .32rem;
  }

  .base_wrapper >>> .van-cell {
    padding: 10px;
    font-size: .36rem;
  }

  .base_wrapper >>> .van-field__left-icon .van-icon {
    font-size: .4rem;
  }
</style>
